package drds.common.db.xml_mapping.parameter_and_result_value_type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Date;


public class TimeOnlyTypeHandler extends BaseTypeHandler<Date> {

  @Override
  public void setNonNullParameter(PreparedStatement preparedStatement, int index, Date parameter, JdbcType jdbcType)
    throws SQLException {
    preparedStatement.setTime(index, new Time(parameter.getTime()));
  }

  @Override
  public Date getNullableResult(ResultSet resultSet, String columnName)
    throws SQLException {
    Time sqlTime = resultSet.getTime(columnName);
    if (sqlTime != null) {
      return new Date(sqlTime.getTime());
    }
    return null;
  }

  @Override
  public Date getNullableResult(ResultSet resultSet, int columnIndex)
    throws SQLException {
    Time sqlTime = resultSet.getTime(columnIndex);
    if (sqlTime != null) {
      return new Date(sqlTime.getTime());
    }
    return null;
  }


}
